#ifndef KINECTSNAPSHOTRECORDERDIALOG_H
#define KINECTSNAPSHOTRECORDERDIALOG_H

#ifdef KINECT

#include <QDialog>

#include "GUI/kinect/kinectdialog.h"
#include "GUI/kinect/kinectsnapshotrecorderframe.h"
#include "GUI/kinect/kinectsnapshotsetframe.h"

#include "Core/Animation/robotaction.h"

#include "Kinect/troykeyframegenerator.h"

namespace Ui {
    class KinectSnapshotRecorderDialog;
}

/**
  * @brief Creates a RobotAction performing an action acted out by the user and captured by the Kinect.
  * However, instead of simply recording all intermediate movements of the user, select keyframes
  * are indicated beforehand, and then as the action is performed each frame is compared to these keyframes
  * and when one is recognized, it is saved.
  */
class KinectSnapshotRecorderDialog : public KinectDialog {
private:
    Q_OBJECT
    Ui::KinectSnapshotRecorderDialog *ui;

    KinectSnapshotSetFrame* _setFrame;
    int _snapshotSet;
    KinectSnapshotRecorderFrame* _recorderFrame;
    int _recorder;

    kinect::TroyKeyframeGenerator* _keyframer;
public:
    explicit KinectSnapshotRecorderDialog(kinect::Kinect* kinect, QWidget *parent = 0);
    ~KinectSnapshotRecorderDialog();
#ifdef WIIMOTE
    void associateWiimote(WiimoteStatusDialog *dialog);
    // As there are times when wiimote commands need to be reloaded when the two QFrames are switched,
    // the actual commands are linked here so they can be refreshed more easily.
    void updateWiimoteCommands();
#endif
    /**
      * @brief Gets the action recorded. Returns null if no action was successfully captured. Ownership of the
      * RobotAction is passed to the caller.
      * Note: This will also stop the preview playback of the action, as it is not copied when the preview is loaded.
      * If this causes problems, it can be changed, but rational for now is that this shouldn't be called until the window
      * is accept()ed or reject()ed anyway.
      */
    RobotAction* getRecordedAction();
protected:
    void kinectKeyFrame(MotionKeyFrame keyFrame);
private slots:
    // Manipulate the current state of recording
    void start();
    void stop();
    void toggle();

    // Adds a snapshot of whatever the current frame is.
    void takeSnapshot();
    // Private methods that handle propogating snapshot insertion and deletion to both QFrames.
    void addSnapshot(int id);
    void deleteSnapshot(int id);

    // Updates the signal/slot and wiimote command linkage when the active QFrame is changed
    void updateFrame(int stackId);
    // Switches between the two QFrames
    void next();
    void prev();
};

#endif

#endif // KINECTSNAPSHOTRECORDERDIALOG_H
